import vuex from "vuex";
import vue from "vue";
import createPersistedState from "vuex-persistedstate";

vue.use(vuex);

export default new vuex.Store({
  state: {
    token: {
      time: "",
      token: "",
      account: "",
      flag: false,
    },
    error: ""
  },


  mutations: {
    updateToken(state, token){
      state.token.time = token.time;
      state.token.token = token.token;
      state.token.flag = token.flag;
      state.token.account = token.account;
    },

    updateError(state, error){
      state.error = error;
    }
  },


  plugins: [createPersistedState({
    storage: window.sessionStorage
  })]
})
